// Learn cc.Class:
//  - https://docs.cocos.com/creator/manual/en/scripting/class.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

cc.Class({
    extends: cc.Component,

    properties: {
        avatar: cc.Sprite,
        // foo: {
        //     // ATTRIBUTES:
        //     default: null,        // The default value will be used only when the component attaching
        //                           // to a node for the first time
        //     type: cc.SpriteFrame, // optional, default is typeof default
        //     serializable: true,   // optional, default is true
        // },
        // bar: {
        //     get () {
        //         return this._bar;
        //     },
        //     set (value) {
        //         this._bar = value;
        //     }
        // },
    },

    // LIFE-CYCLE CALLBACKS:

    // onLoad () {},

    start() {

        let _this = this
        // 远程 url 带图片后缀名
        // https://www.baidu.com/img/flexible/logo/pc/result.png
        // let remoteUrl = "http://c-ssl.duitang.com/uploads/item/201807/14/20180714183007_bvlpc.jpg";
        let remoteUrl = "https://upfile1.hicloud.com/FileServer/image/b.0260086200300495793.20200213101340.bQsLEsLvcOUGPqe2xdLnGeFwMalTN874.0001.hwid.null.DA3CEB054DA36307AFE14B02B32E925CE606B7F64BD5073C70DE79E1C0813013.jpg";
        
        cc.assetManager.loadRemote(remoteUrl, function (err, texture) {
            console.log("cc.assetManager.loadRemote")
            // _this.avatar.spriteFrame.setTexture(texture);
            // Use texture to create sprite frame


            var spf = new cc.SpriteFrame();
            spf.initWithTexture(texture);
            _this.avatar.spriteFrame = spf;
        });
    },

    // update (dt) {},
});
